package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.NewEnergyMonitor;
import com.ruoyi.mes.service.INewEnergyMonitorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实时能耗监控Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/mes/energyMonitor")
public class NewEnergyMonitorController extends BaseController
{
    @Autowired
    private INewEnergyMonitorService newEnergyMonitorService;

    /**
     * 查询实时能耗监控列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyMonitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewEnergyMonitor newEnergyMonitor)
    {
        startPage();
        List<NewEnergyMonitor> list = newEnergyMonitorService.selectNewEnergyMonitorList(newEnergyMonitor);
        return getDataTable(list);
    }

    /**
     * 导出实时能耗监控列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyMonitor:export')")
    @Log(title = "实时能耗监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewEnergyMonitor newEnergyMonitor)
    {
        List<NewEnergyMonitor> list = newEnergyMonitorService.selectNewEnergyMonitorList(newEnergyMonitor);
        ExcelUtil<NewEnergyMonitor> util = new ExcelUtil<NewEnergyMonitor>(NewEnergyMonitor.class);
        util.exportExcel(response, list, "实时能耗监控数据");
    }

    /**
     * 获取实时能耗监控详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:energyMonitor:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(newEnergyMonitorService.selectNewEnergyMonitorByRecordId(recordId));
    }

    /**
     * 新增实时能耗监控
     */
    @PreAuthorize("@ss.hasPermi('mes:energyMonitor:add')")
    @Log(title = "实时能耗监控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewEnergyMonitor newEnergyMonitor)
    {
        return toAjax(newEnergyMonitorService.insertNewEnergyMonitor(newEnergyMonitor));
    }

    /**
     * 修改实时能耗监控
     */
    @PreAuthorize("@ss.hasPermi('mes:energyMonitor:edit')")
    @Log(title = "实时能耗监控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewEnergyMonitor newEnergyMonitor)
    {
        return toAjax(newEnergyMonitorService.updateNewEnergyMonitor(newEnergyMonitor));
    }

    /**
     * 删除实时能耗监控
     */
    @PreAuthorize("@ss.hasPermi('mes:energyMonitor:remove')")
    @Log(title = "实时能耗监控", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(newEnergyMonitorService.deleteNewEnergyMonitorByRecordIds(recordIds));
    }
}
